home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
fonttools
/
frompsf.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
150 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* frompsf -
* Convert a .psf font into the Hex format.
*
* Paul Haeberli - 1990
*/
#include "stdio.h"
#include "ctype.h"
unsigned char *charfiledata();
FILE *inf, *outf;
int macfont;
sizeoffile(f)
FILE *f;
{
register int pos, ret;
pos = ftell(f);
if ((ret = fseek(f,0,2)) < 0) {
fprintf(stderr,"sizeoffile: seek error\n");
exit(1);
}
ret = ftell(f);
if (fseek(f,pos,0) < 0) {
fprintf(stderr,"sizeoffile: seek error\n");
exit(1);
}
return ret;
}
unsigned char *charfiledata(f)
FILE *f;
{
unsigned char *dat;
int nbytes;
nbytes = sizeoffile(f);
if (fseek(f,0,0) < 0) {
fprintf(stderr,"charfiledata: seek error\n");
exit(1);
}
dat = (unsigned char *)malloc(nbytes);
fread(dat,1,nbytes,f);
if (fseek(f,0,0) < 0) {
fprintf(stderr,"charfiledata: seek error\n");
exit(1);
}
return dat;
}
main(argc,argv)
int argc;
char **argv;
{
int d;
char str[256];
int i, temp;
int nbytes, maxpos, patlen;
unsigned char *filedata;
int beginpos, endpos, count;
int col;
if(argc<3) {
fprintf(stderr,"usage: frompsf in.psf out.hex\n");
exit(1);
}
inf = fopen(argv[1],"r");
if(!inf) {
fprintf(stderr,"frompsf: can't open input file\n");
exit(1);
}
outf = fopen(argv[2],"w");
macfont = 0;
nbytes = sizeoffile(inf);
filedata = charfiledata(inf);
patlen = strlen("currentfile eexec\r");
maxpos = nbytes-patlen;
for(i=0; i<nbytes; i++) {
if(strncmp(filedata+i,"currentfile eexec\r",patlen) == 0) {
beginpos = i+patlen;
break;
}
}
if(i == nbytes) {
fprintf(stderr,"frompsf: eexec string not found\n");
exit(1);
}
for(i=0; i<beginpos; i++) {
if(filedata[i] == '\r')
filedata[i] = '\n';
}
fwrite(filedata,1,beginpos,outf);
i = nbytes;
count = 0;
while(i--) {
if(filedata[i] == '0') {
count++;
if(count == 512)
break;
} else if(!isspace(filedata[i])) {
count = 0;
}
}
if(count != 512) {
fprintf(stderr,"frompsf: can't find 512 zeros!!\n");
exit(1);
}
endpos = i;
col = 0;
for(i=beginpos; i<endpos; i++) {
fprintf(outf,"%02x",filedata[i]);
col++;
if(col == 32) {
col = 0;
fprintf(outf,"\n");
}
}
if(col != 0)
fprintf(outf,"\n");
for(i=endpos; i<nbytes; i++) {
if(filedata[i] == '\r')
filedata[i] = '\n';
}
fwrite(filedata+endpos,1,nbytes-endpos,outf);
fclose(outf);
exit(0);
}